﻿using UnityEngine;

namespace HK.Editor.GUIEx.Styles
{
    public class ColorScopeBase : GUI.Scope
    {
        protected readonly Color LastColor;
        protected readonly bool Enable;
        
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="iColor">颜色</param>
        /// <param name="iEnable">可用/不可用</param>
        public ColorScopeBase(Color iColor, bool iEnable = true)
        {
            LastColor = GUI.backgroundColor;
            Enable = iEnable;
        }
        
        protected override void CloseScope()
        {
            if(!Enable) return;
            GUI.color = LastColor;
        }
    }

    /// <summary>
    /// GUI颜色
    /// </summary>
    public sealed class ColorScope : ColorScopeBase
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="iColor">颜色</param>
        /// <param name="iEnable">可用/不可用</param>
        public ColorScope(Color iColor, bool iEnable = true) : base(iColor, iEnable)
        {
            if(!Enable) return;
            GUI.color = iColor;
        }
    }

    /// <summary>
    /// GUI颜色背景区域
    /// <para>* 注意：对文本无效</para>
    /// </summary>
    public sealed class BackgroundColorScope : ColorScopeBase
    {
        public BackgroundColorScope(Color iColor, bool iEnable = true) : base(iColor, iEnable)
        {
            if(!Enable) return;
            GUI.backgroundColor = iColor;
        }
        
        protected override void CloseScope()
        {
            if(!Enable) return;
            GUI.backgroundColor = LastColor;
        }
    }

}